package com.oracle.lingshangejia.activity.special;

import android.app.DatePickerDialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.oracle.lingshangejia.Constant;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.adapter.special.HighBloodPressureExtendableListAdapter;
import com.oracle.lingshangejia.bean.DataBean;
import com.oracle.lingshangejia.bean.User;
import com.oracle.lingshangejia.dialog.LoadingViewDialog;
import com.oracle.lingshangejia.utils.MyLogger;
import com.oracle.lingshangejia.utils.MyToast;

import org.json.JSONObject;

import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
//高血压
public class HighBloodPpressureActivity extends AppCompatActivity {
    private LoadingViewDialog mLoadingView;
    private ExpandableListView expandableListView;
    private HighBloodPressureExtendableListAdapter archivesExtendableListAdapter;
   // private ArchivesSQLiteHelper sqLiteHelper;
    private Map<Object,Object> mValues = new HashMap<>();
    private  String url = Constant.baseurl+"online/zxdagxy/save";

    public void showLoading(){
        mLoadingView = new LoadingViewDialog();
        mLoadingView.show(getSupportFragmentManager(),"" );
    }
    public void dismissLoading(){
        if (mLoadingView != null){
            mLoadingView.dismiss();
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.add_high_blood_pressure_archives_activity);
        Toolbar toolbar = (Toolbar)findViewById(com.oracle.children.R.id.toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        expandableListView = findViewById(R.id.expend_list);
        expandableListView.setGroupIndicator(null);
        String[] archivesStr = getResources().getStringArray(R.array.gxy_archives);
        archivesExtendableListAdapter = new HighBloodPressureExtendableListAdapter(archivesStr);
        expandableListView.setAdapter(archivesExtendableListAdapter);
        // 添加末尾提交按钮
        View foot = LayoutInflater.from(this).inflate(R.layout.archives_foot_submit, null);
        expandableListView.addFooterView(foot);

        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return /*checkBasicInfoIsError()*/false;
            }
        });

        expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                int count = expandableListView.getExpandableListAdapter().getGroupCount();
                for (int i = 0; i < count; i++) {
                    if (i != groupPosition) {
                        expandableListView.collapseGroup(i);
                    }
                }
            }
        });
        expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
            @Override
            public void onGroupCollapse(int groupPosition) {
                View[] views = ((HighBloodPressureExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
                View view = views[groupPosition];
                if (view == null) {
                    return;
                }
                Map<String, String> values = null;
                switch (groupPosition) {
                    case 0:
                        values = getBasicInfoValues();
                        break;
                    case 1:
                        values = getPhysicalSignsLifestyleValues(view);
                        break;
                    case 2:
                        values = getDrugUsageValues(view);
                        break;
                    case 3:
                        values = getOtherMessageValues(view);
                        break;
                }
            /*    System.out.println("数据：" + values);
                if (values != null && values.size() > 0)
                    saveValues(values);*/

            }
        });

        expandableListView.expandGroup(0);
       // sqLiteHelper = new ArchivesSQLiteHelper(this);
       // sqLiteHelper.onUpgrade(sqLiteHelper.getReadableDatabase(),1,1);
    }


    /**
     * 检查用户名、身份证号和本人联系电话是否正确填写
     *
     * @return 数据不正确返回true，正确返回false
     */
    private boolean checkBasicInfoIsError() {
        Map<String, String> basicInforValues = getBasicInfoValues();
        String xm = (String) basicInforValues.get("xm");

        // 姓名非空验证
        if (xm == null || xm.length() == 0) {
            Toast.makeText(getApplicationContext(), "姓名必须填写", Toast.LENGTH_SHORT).show();
            return true;
        }


        return false;
    }

    /**
     * Activity销毁时清空SQLite中数据
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
       // sqLiteHelper.deleteAll();
    }

    /**
     * 存储临时数据到SQLite
     * @param values
     */
    private void saveValues(Map<String, String> values) {

    }

    /*

     * 第一页，基本信息
     */

    private Map<String, String> getBasicInfoValues() {
        View[] views = ((HighBloodPressureExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
        View view = views[0];
        Map<String, String> params = new HashMap<>();
       /* //居民ID
        String residentID="";
        //医生ID
        String doctorID="";
        // 姓名
        String username1 = "";
        // 编号
        String number1 = "";
        // 随访日期
        String birthday1 = "";
        // 随访方式
        String way1 = "";*/
        //症状
        String symptom1 ="";
        //其他症状
        String text1 ="";
        // 血压
        String bloodpressure1 = "";
        String bloodpressure2 = "";
        // 体重
        String weight1 = "";
        String weight11 ="";
        // 体质指数
        String constitutionalindex1 = "";
        String constitutionalindex11 = "";
        // 心率
        String heartrate1 = "";
        // 其他
        String other1 = "";

        /*residentID = ((EditText) view.findViewById(R.id.hypertension_residentID)).getText().toString().trim();
        doctorID = ((EditText) view.findViewById(R.id.hypertension_symptom_doctorID)).getText().toString().trim();
        username1 = ((EditText) view.findViewById(R.id.hypertension_symptom_username1)).getText().toString().trim();
        number1 = ((EditText) view.findViewById(R.id.hypertension_symptom_number1)).getText().toString().trim();
        birthday1 = ((TextView) view.findViewById(R.id.hypertension_symptom_birthday1)).getText().toString().trim();
        way1 = ((Spinner) view.findViewById(R.id.hypertension_way1)).getSelectedItem().toString().trim();
        way1 = way1.substring(0, way1.indexOf(" "));*/
        View[] symptom1Views = getViews(view.findViewById(R.id.hypertension_symptom1));
        for (int i = 0; i < symptom1Views.length; i++) {
            if (symptom1Views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) symptom1Views[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    symptom1 += s;
                    symptom1 += ",";
                }
            }
        }

        if (symptom1.length() != 0) {
            symptom1 = symptom1.substring(0, symptom1.length() - 1);
        }
        text1 = ((EditText) view.findViewById(R.id.hypertension_symptom_other_text1)).getText().toString().trim();
        bloodpressure1 = ((EditText) view.findViewById(R.id.hypertension_bloodpressure1)).getText().toString().trim();
        bloodpressure2 = ((EditText) view.findViewById(R.id.hypertension_bloodpressure2)).getText().toString().trim();
        weight1 = ((EditText) view.findViewById(R.id.hypertension_weight1)).getText().toString().trim();
        weight11= ((EditText) view.findViewById(R.id.hypertension_weight11)).getText().toString().trim();
        constitutionalindex1 = ((EditText) view.findViewById(R.id.hypertension_constitutionalindex1)).getText().toString().trim();
        constitutionalindex11= ((EditText) view.findViewById(R.id.hypertension_constitutionalindex11)).getText().toString().trim();
        heartrate1 = ((EditText) view.findViewById(R.id.hypertension_heartrate1)).getText().toString().trim();
        other1 = ((EditText) view.findViewById(R.id.hypertension_oher1)).getText().toString().trim();



   /*     params.put("jm_id", residentID);
        params.put("ys_id", doctorID);
        params.put("xm", username1);
        params.put("bh", number1);
        params.put("rq", birthday1);
        params.put("sffs", symptom1);*/
        params.put("gxyZz",symptom1);//症状
        params.put("gxyZzQt",text1) ;//症状其他
        params.put("gxyTzXyss",bloodpressure1);//血压收缩率  改String
        params.put("gxyTzXysz",bloodpressure2);///血压_舒张率  改String
        params.put("gxyTzTz", weight1);//体重
      //  params.put("gxy_tz_tz", weight11);//
        params.put("gxyTzTzzs", constitutionalindex1);//体重指数
     //   params.put("gxy_tz_tzzs", constitutionalindex11);//
        params.put("gxyTzXl", heartrate1);//心率
        params.put("gxyTzQt", other1);// 其他
        mValues.putAll(params);
        MyLogger.i(new JSONObject(params).toString());
        return params;
    }

    /*

     * 第二页，体征和生活方式
     */

    private Map<String, String> getPhysicalSignsLifestyleValues(View view) {

        Map<String, String> params = new HashMap<>();
        // 日吸烟量
        String daysmoking1 = "";
        // 日饮酒量
        String daydrinking1 = "";
        // 运动
        String exercise11 = "";
        String exercise12 = "";
        String exercise13 = "";
        String exercise14 = "";
        // 摄盐情况
        String salty1 = "";
        String thin1 ="";
        //心理调整
        String psychologist1 ="";
        //遵医行为
        String followdoctor1 ="";
        // 辅助检查
        String examination1 = "";
        // 服药依从性
        String medication1 = "";
        // 药物不良反应
        String drugreaction1 = "";
        // 药物不良反应名称
        String havedrugreaction1 = "";
        // 此次随访分类
        String classify1 = "";

        daysmoking1 = ((EditText) view.findViewById(R.id.hypertension_daysmoking1)).getText().toString().trim();
        daydrinking1 = ((EditText) view.findViewById(R.id.hypertension_daydrinking1)).getText().toString().trim();
        exercise11 = ((EditText) view.findViewById(R.id.hypertension_exercise11)).getText().toString().trim();
        exercise12 = ((EditText) view.findViewById(R.id.hypertension_exercise12)).getText().toString().trim();
      //  exercise13 = ((EditText) view.findViewById(R.id.hypertension_exercise13)).getText().toString().trim();
      //  exercise14 = ((EditText) view.findViewById(R.id.hypertension_exercise14)).getText().toString().trim();
        salty1 = ((Spinner) view.findViewById(R.id.hypertension_salty1)).getSelectedItem().toString().trim();
        salty1 = salty1.substring(0, salty1.indexOf(" "));
       // thin1 = ((Spinner) view.findViewById(R.id.hypertension_thin1)).getSelectedItem().toString().trim();
       // thin1 = thin1.substring(0, thin1.indexOf(" "));
        psychologist1 = ((Spinner) view.findViewById(R.id.hypertension_psychologist1)).getSelectedItem().toString().trim();
        psychologist1 = psychologist1.substring(0, psychologist1.indexOf(" "));
        followdoctor1 = ((Spinner) view.findViewById(R.id.hypertension_followdoctor1)).getSelectedItem().toString().trim();
        followdoctor1 = followdoctor1.substring(0, followdoctor1.indexOf(" "));
        examination1 = ((EditText) view.findViewById(R.id.hypertension_examination1)).getText().toString().trim();
        medication1 = ((Spinner) view.findViewById(R.id.hypertension_medication1)).getSelectedItem().toString().trim();
        medication1 = medication1.substring(0, medication1.indexOf(" "));

        View[] drugreaction1Views = getViews(view.findViewById(R.id.hypertension_drugreaction1));
        for (int i = 0; i < drugreaction1Views.length; i++) {
            if (drugreaction1Views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) drugreaction1Views[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    drugreaction1=s;
                    /*drugreaction1 += s;
                    drugreaction1 += ",";*/
                }
            }
        }
        RadioButton radioButton = view.findViewById(R.id.hypertension_nonedrugreaction1);
        if (radioButton.isChecked()){
            drugreaction1 = "1";
        }else {
            drugreaction1 = "2";
        }
        MyLogger.i(drugreaction1+"不良反应");

       /* if (drugreaction1.length() != 0) {
            drugreaction1 = drugreaction1.substring(0, drugreaction1.length() - 1);
        }*/
        havedrugreaction1 = ((EditText) view.findViewById(R.id.hypertension_havedrugreaction1)).getText().toString().trim();

        classify1 = ((Spinner) view.findViewById(R.id.hypertension_classify1)).getSelectedItem().toString().trim();
        classify1 = classify1.substring(0, classify1.indexOf(" "));

        params.put("gxyShfszdRxyl", daysmoking1);//日吸烟量
        params.put("gxyShfszdRyjl", daydrinking1);//日酒量
        params.put("gxyShfszdZyd", exercise11);//运动周
        params.put("gxyShfszdCyd", exercise12);//运动分钟
      ///  params.put("gxy_shfszd_zyd", exercise13);
      //  params.put("gxy_shfszd_cyd", exercise14);
        params.put("gxyShfszdSyqk",salty1);//摄盐情况
      //  params.put("gxy_shfszd_syqk",thin1);
        params.put("gxyShfszdXltz", psychologist1);//心理指导
        params.put("gxyShfszdZyxw", followdoctor1);//遵医行为
        params.put("fzjc", examination1);//辅助检查
        params.put("gxyFyycx", medication1);//服药依懒性
        params.put("gxyYwblfy", drugreaction1);//不良反应
        params.put("gxyYwblfyName", havedrugreaction1);//药物不良反应名称  新加
        params.put("gxyCcsffl", classify1);//此次随访分类
        MyLogger.i(drugreaction1+"不良反应");
        mValues.putAll(params);
        return params;
    }


    /*

     * 第三页，用药情况
     */

    private Map<String, String> getDrugUsageValues(View view) {

        Map<String, String> params = new HashMap<>();
        // 药物名称1用法用量
        String drugname11 = "";
        //每日次数
        String drugname12 = "";
        //每次用药量
        String drugname13 = "";
        // 药物名称2用法用量
        String drugname14 = "";
        //每日次数
        String drugname15 = "";
        //每次用药量
        String drugname16 = "";
        // 药物名称3用法用量
        String drugname17 = "";
        //每日次数
        String drugname18 = "";
        //每次用药量
        String drugname19 = "";
        // 其他药物名称用法用量
        String drugname110 = "";
        //每日次数
        String drugname111 = "";
        //每次用药量
        String drugname112 = "";

        drugname11 = ((EditText) view.findViewById(R.id.hypertension_drugname11)).getText().toString().trim();
        drugname12 = ((EditText) view.findViewById(R.id.hypertension_drugname12)).getText().toString().trim();
        drugname13 = ((EditText) view.findViewById(R.id.hypertension_drugname13)).getText().toString().trim();
        drugname14 = ((EditText) view.findViewById(R.id.hypertension_drugname14)).getText().toString().trim();
        drugname15 = ((EditText) view.findViewById(R.id.hypertension_drugname15)).getText().toString().trim();
        drugname16 = ((EditText) view.findViewById(R.id.hypertension_drugname16)).getText().toString().trim();
        drugname17 = ((EditText) view.findViewById(R.id.hypertension_drugname17)).getText().toString().trim();
        drugname18 = ((EditText) view.findViewById(R.id.hypertension_drugname18)).getText().toString().trim();
        drugname19 = ((EditText) view.findViewById(R.id.hypertension_drugname19)).getText().toString().trim();
        drugname110 = ((EditText) view.findViewById(R.id.hypertension_drugname110)).getText().toString().trim();
        drugname111 = ((EditText) view.findViewById(R.id.hypertension_drugname111)).getText().toString().trim();
        drugname112 = ((EditText) view.findViewById(R.id.hypertension_drugname112)).getText().toString().trim();

        params.put("gxyYyqkYwmc1", drugname11);//药物名称1
        params.put("gxyYyqkMejc1", drugname12);//每日次数1
        params.put("gxyYyqkMcjk1", drugname13);//每次几颗1
        params.put("gxyYyqkYwmc2", drugname14);//2
        params.put("gxyYyqkMejc2", drugname15);//2
        params.put("gxyYyqkMcjk2", drugname16);//2
        params.put("gxyYyqkYwmc3", drugname17);//3
        params.put("gxyYyqkMejc3", drugname18);//3
        params.put("gxyYyqkMcjk3", drugname19);//3
        params.put("gxyYyqkYwmcQt", drugname110);//其他药物名称
        params.put("gxyYyqkMejcQt", drugname111);//每日次数
        params.put("gxyYyqkMcjkQt", drugname112);//每次几颗
        mValues.putAll(params);
        return params;
    }

    /*

     * 第四页，其他信息
     */

    private Map<String, String> getOtherMessageValues(View view) {
        Map<String, String> params = new HashMap<>();
        //转诊建议
        String referraladvice1 ="";
        String havereferraladvice1 ="";
        // 转诊原因
        String referralreason1 = "";
        //机构及科别
        String organization1 = "";
        //下次随访日期
        String followupdate1 = "";
        // 医生签名
        String signature1 = "";


       /* View[] referraladvice1Views = getViews(view.findViewById(R.id.hypertension_referraladvice1));
        for (int i = 0; i < referraladvice1Views.length; i++) {
            if (referraladvice1Views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) referraladvice1Views[i];
                if (cb.isChecked()) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    referraladvice1 += s;
                    referraladvice1 += ",";
                }
            }
        }*/
       RadioButton radioButton = view.findViewById(R.id.hypertension_havereferraladvice);
       if (radioButton.isChecked()){
           referraladvice1 ="1";
       }else {
           referraladvice1 ="2";
       }

        /*if (referraladvice1.length() != 0) {
            referraladvice1 = referraladvice1.substring(0, referraladvice1.length() - 1);
        }*/
        //havereferraladvice1 = ((EditText) view.findViewById(R.id.hypertension_havereferraladvice1)).getText().toString().trim();
        referralreason1 = ((EditText) view.findViewById(R.id.hypertension_referralreason1)).getText().toString().trim();
        organization1 = ((EditText) view.findViewById(R.id.hypertension_organization1)).getText().toString().trim();
        followupdate1 = ((TextView) view.findViewById(R.id.hypertension_followupdate1)).getText().toString().trim();
        signature1 = ((EditText) view.findViewById(R.id.hypertension_signature1)).getText().toString().trim();
        MyLogger.i(referraladvice1);
        params.put("zzjy", referraladvice1);//转诊建议
       // params.put("zzjy_nr", havereferraladvice1);///转诊建议内容   新增
        params.put("zzyy", referralreason1);///转诊原因
        params.put("zzjg", organization1);///机构
        params.put("zzks", organization1);/////科室
        params.put("scsfsj", followupdate1);//下次随访日期
        params.put("sfYsqm", signature1);///医生签名
        mValues.putAll(params);
        return params;
    }


    /**
     * 症状按钮点击事件
     */
    public void onAllergyClick(View view) {
        CheckBox none = findViewById(R.id.hypertension_symptom_none1);
        CheckBox other = findViewById(R.id.hypertension_symptom_other1);
        EditText otherText = findViewById(R.id.hypertension_symptom_other_text1);
        View[] views = getViews(findViewById(R.id.hypertension_symptom1));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.hypertension_symptom_none1 && cb.getId() != R.id.hypertension_symptom_none1) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else if (view.getId() != R.id.hypertension_symptom_none1) {
                    if (cb.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }
    /**
     * 药物不良反应按钮点击事件处理
     */
    public void changeNationalEnableEdit(View view) {
        EditText ed = findViewById(R.id.hypertension_havedrugreaction1);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.hypertension_nonedrugreaction1) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /**
     * 转诊建议按钮点击事件处理
     */
    public void changeNationalEnableEdit1(View view) {
       /* EditText ed = findViewById(R.id.hypertension_havereferraladvice1);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.hypertension_nonereferraladvice1) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }*/
    }

    /**
     * Toolbar的事件---返回
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }
    /**
     * 点击日期选择框弹出DatePickerDialog
     */
    private Calendar calendar;
    private DatePickerDialog dialog;

    public void onTimeViewClick(final View v) {
        calendar = Calendar.getInstance();
        dialog = new DatePickerDialog(HighBloodPpressureActivity.this,
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year,
                                          int monthOfYear, int dayOfMonth) {
                        TextView tv = (TextView) v;
                        String month;
                        String day;
                        if (monthOfYear <9){
                            month = "0"+(monthOfYear+1);
                        }else {
                            month = ""+(monthOfYear+1);
                        }
                        if (dayOfMonth <10){
                            day = "0"+dayOfMonth;
                        }else {
                            day = dayOfMonth + "";
                        }
                        tv.setText(year + "-" + month  + "-" + day);
                    }
                }, calendar.get(Calendar.YEAR), calendar
                .get(Calendar.MONTH), calendar
                .get(Calendar.DAY_OF_MONTH));
        dialog.show();
    }



    /**
     * 获取子视图
     */
    private View[] views;

    private View[] getViews(View view) {
        views = new View[0];
        parseView(view);
        return views;
    }

    private void parseView(View view) {
        if (view instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) view;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View v = vg.getChildAt(i);
                parseView(v);
            }
        } else {
            views = Arrays.copyOf(views, views.length + 1);
            views[views.length - 1] = view;
        }
    }

    /**
     * 从SQLite中读取需提交的数据
     */
   /* private Map<String, Object> getParams() {
        // 收起列表保证数据全部存入SQLite
        int count = expandableListView.getExpandableListAdapter().getGroupCount();
        for (int i = 0; i < count; i++) {
            expandableListView.collapseGroup(i);
        }

        Map<String, Object> params = new HashMap<>();
        String xm = getBasicInfoValues().get("xm");
        Cursor cursor = sqLiteHelper.queryByIdCard(new String[]{xm});
        if (cursor.moveToFirst()) {
            do {
                for (int i = 1; i < cursor.getColumnCount(); i++) {
                    String name = cursor.getColumnName(i);
                    while (true) {
                        int index = name.indexOf("_");
                        if(index == -1) {
                            break;
                        }
                        name = name.substring(0,index) + name.substring(index + 1, index + 2).toUpperCase() + name.substring(index + 2);
                    }
                    System.out.println("提交的字段名是：" + name);
                    if(name.equals("ysId") || name.equals("xm")|| name.equals("bh")|| name.equals("rq")|| name.equals("sffs")
                            ||name.equals("gxyZz") || name.equals("gxyZzQt")|| name.equals("gxyTzXyss")|| name.equals("gxyTzXysz")|| name.equals("gxyTzTz")
                            ||name.equals("gxyTzTz") || name.equals("gxyTzTzzs")|| name.equals("gxyTzTzzs")|| name.equals("gxyTzXl")|| name.equals("gxyTzQt")
                            || name.equals("gxyShfszdRxyl")|| name.equals("gxyShfszdRyjl")|| name.equals("gxyShfszdZydv")|| name.equals("gxyShfszdCyd")|| name.equals("gxyShfszdZyd")
                            || name.equals("gxyShfszdCyd")|| name.equals("gxyShfszdSyqk")|| name.equals("gxyShfszdSyqk")|| name.equals("gxyShfszdXltz")|| name.equals("gxyShfszdZyxw")
                            || name.equals("fzjc")|| name.equals("gxyFyycx")|| name.equals("gxyYwblfy")|| name.equals("gxyYwblfy")|| name.equals("gxyCcsffl")
                            || name.equals("gxyYyqkYwmc1")|| name.equals("gxyYyqkMejc1")|| name.equals("gxyYyqkMcjk1")|| name.equals("gxyYyqkYwmc2")|| name.equals("gxyYyqkMejc2")
                            || name.equals("gxyYyqkMcjk2")|| name.equals("gxyYyqkYwmc3")|| name.equals("gxyYyqkMejc3")|| name.equals("gxyYyqkMcjk3")|| name.equals("gxyYyqkYwmcQt")
                            || name.equals("gxyYyqkMejcQt")|| name.equals("gxyYyqkMcjkQt") || name.equals("zzjy")|| name.equals("zzjy")|| name.equals("zzyy")|| name.equals("zzjg")
                            ||name.equals("zzks") || name.equals("scsfsj")|| name.equals("sfYsqm")){
                        params.put(name, cursor.getInt(i));
                    } else {
                        params.put(name, cursor.getString(i));
                    }

                }
            } while (cursor.moveToNext());
        }
        return params;
    }*/



    /**
     * 提交数据
     */
    public void onClickSubmit(View view) {
        showLoading();
        int count = expandableListView.getExpandableListAdapter().getGroupCount();
        for (int i = 0; i < count; i++) {
            expandableListView.collapseGroup(i);
        }
        /*if (checkBasicInfoIsError()) {
            return;
        }*/
       /// Map<String, Object> params = getParams();

        //token = "f8dba3521da64857b8b6ebebf0c34d39";
        mValues.put("token", User.getToken());
        mValues.put("jmId",getIntent().getIntExtra("jmid", 0) );
        mValues.put("userId", User.getUserId());//社区医生id;
        mValues.put("mark", 1);
        //随访id
        int id = getIntent().getIntExtra("id", 0);
        if (id !=0){
            mValues.put("id", id);
        }
        JSONObject jsonObject = new JSONObject(mValues);
        MyLogger.i(jsonObject.toString());
        MyLogger.i("提交");

        OkGo.<String>post(url)
                .upJson(jsonObject.toString())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        dismissLoading();
                        String body = response.body();
                        MyLogger.i(body);
                        Gson gson = new Gson();
                        DataBean dataBean = gson.fromJson(body, DataBean.class);
                        if(dataBean.getCode()==0){
                            MyToast.show("提交成功");
                            finish();
                        }else {
                           MyToast.show(dataBean.getMsg());
                        }


                    }

                    @Override
                    public void onError(Response<String> response) {
                        Toast.makeText(getApplicationContext(), "服务器暂时无法访问，稍后再试！", Toast.LENGTH_LONG).show();
                    }
                });
    }

}
